package com.example.demo.web.Controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import com.example.demo.web.services.LockService;


@Controller
public class LockController {
	private LockService lockService;
    @Autowired
    public void setRightService(LockService lockService){
        this.lockService = lockService;
    }
    
    @RequestMapping(value="/getlocklist",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String getlocklist(@RequestBody String objnode,HttpServletRequest request,HttpSession session) throws IOException{
		return lockService.getlocklist(objnode,request,session);
		
	}
    
    @RequestMapping(value = "/lockadd",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> lockadd(@RequestBody String objnode,HttpServletRequest request, HttpSession session) throws Exception{    
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._insertlock(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/lockedit",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> lockedit(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws Exception{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._updatelock(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/lockdel",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> lockdel(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._lockDelete(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/lockoff",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> lockoff(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._lockOff(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/getOpenLogs",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> getOpenLogs(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._getOpenLogs(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/getLockoffLogs",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> getLockoffLogs(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._getLockoffLogs(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value="/getUserLocks",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getUserLocks(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getUserLocks(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/findLocksByLoginUser",method=RequestMethod.GET,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> findLocksByLoginUser(HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.findLocksByLoginUser(deferredResult,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getLockUsers",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getLockUsers(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getLockUsers(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getLocksByMissionid",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getLocksByMissionid(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getLocksByMissionid(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/lockauth",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> lockauth(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.lockauth(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getLockList_template",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getLockList_template(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getLockList_template(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getSingleLockList_template",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getSingleLockList_template(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getSingleLockList_template(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getDoubleLockList_template",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getDoubleLockList_template(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getDoubleLockList_template(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getUserNamelistByLock",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> getUserNamelistByLock(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService.getUserNamelistByLock(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/lockstransfer",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> lockstransfer(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService._lockstransfer(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/lockstransfer_init",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> lockstransfer_init(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();  	
    	lockService._lockstransfer_init(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getkeylist",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String getkeylist(@RequestBody String objnode,HttpServletRequest request,HttpSession session) throws IOException{
		return lockService.getkeylist(objnode,request,session);
		
	}
    
    @RequestMapping(value = "/keyadd",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> keyadd(@RequestBody String objnode,HttpServletRequest request, HttpSession session) throws Exception{    
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._insertkey(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/keyedit",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> keyedit(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws Exception{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._updatekey(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/keydel",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> keydel(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._keyDelete(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/keyoff",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> keyoff(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService._keyOff(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/addtestlock",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> addtestlock(@RequestBody String objnode,HttpServletRequest request, HttpSession session) throws Exception{    
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        lockService.addtestlock(deferredResult,objnode,request, session);
        return deferredResult;
    }
}
